import * as http from "http";
import loginUtil from './crypto_util';
import getDb from './config/db';

const dbConnect = getDb();
const hs = http.createServer((req, resp) => {
    let header = req.headers;
    let authorization = header.authorization;
    let url = req.url;

    //鉴权模块
    // if (url == '/login') {
    //     try {
    //         //TODO:登录处理
    //         // loginUtil.crypto
    //     } catch (error) {

    //     }
    // } else {
    //     try {
    //         loginUtil.isLogin(authorization);
    //     } catch (error) {
    //         resp.statusCode = 403;
    //         resp.end(JSON.stringify({
    //             status: 403,
    //             message: error
    //         }));
    //     }
    // }
    route(req, resp);
    resp.end();
});
const METHOD = {
    POST: 'POST',
    GET: 'GET'
};

function route(req: http.IncomingMessage, resp: http.ServerResponse) {
    let method: string = req.method;
    let url: string = req.url;
    switch (url) {
        case '/login':

            break;
        default:
            resp.statusCode = 404;
            resp.end(`route ${url} not exist!`);
    }
}

hs.listen(3000, () => {
    console.log('-------------服务启动,端口3000-------------');
});